package com.wodan.zhongjinjicang.model;

import org.apache.ibatis.session.RowBounds;

import java.util.Date;

/**
 * 查询参数
 * @ClassName: QueryParam 
 * @author Administrator
 * @date 2015-1-17 上午9:46:56 
 * @history 
 *
 */
public class QueryParam implements Cloneable {
	/**
	 * 时间戳
	 */
	private Long timestamp = System.currentTimeMillis();

	/**
	 * 页大小
	 */
	private Integer page_size = Integer.valueOf(10);

	/**
	 * 页号
	 */
	private Integer page_num = Integer.valueOf(1);

	/**
	 * getTimestamp
	 * @Description:
	 * @return
	 */
	public Long getTimestamp() {
		return timestamp;
	}

	/**
	 * setTimestamp
	 * @Description:
	 * @param timestamp
	 */
	public void setTimestamp(Long timestamp) {
		if(timestamp != null)
			this.timestamp = timestamp;
	}
	
	/**
	 * getDate
	 * @Description:
	 */
	public Date convertToDate() {
		return new Date(timestamp);
	}

	/**
	 * getPage_size
	 * @Description:
	 * @return
	 */
	public Integer getPage_size() {
		return page_size;
	}

	/**
	 * setPage_size
	 * @Description:
	 * @param page_size
	 */
	public void setPage_size(Integer page_size) {
		if(page_size != null)
			this.page_size = page_size;
	}

	/**
	 * getPage_num
	 * @Description:
	 * @return
	 */
	public Integer getPage_num() {
		return page_num;
	}

	/**
	 * setPage_num
	 * @Description:
	 * @param page_num
	 */
	public void setPage_num(Integer page_num) {
		if(page_num != null)
			this.page_num = page_num;
	}
	
	/**
	 * computeOffset
	 * @Description:
	 * @return
	 */
	public int computeOffset() {
		return (page_num.intValue() - 1) * page_size.intValue();
	}
	
	/**
	 * computeLimit
	 * @Description:
	 * @return
	 */
	public int computeLimit() {
		return page_size.intValue();
	}
	
	/**
	 * 创建RowBounds
	 * @Description:
	 * @return
	 */
	public RowBounds createRowBounds() {
		return new RowBounds(computeOffset(), computeLimit());
	}
	
	public QueryParam clone() {
		try {
			return (QueryParam)super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
			return null;
		}
	}
}
